home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / kaffe / readClassConfig.h < prev    next >
C/C++ Source or Header  |  1996-02-17  |  2KB  |  99 lines

  1. /*
  2.  * readClassConfig.h
  3.  * Configure the class reader.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. #ifndef __readclassconfig_h
  15. #define __readclassconfig_h
  16.  
  17. #include "classMethod.h"
  18. #include "errors.h"
  19. #include "lookup.h"
  20.  
  21. /*
  22.  * Add a class to the system.
  23.  */
  24. #define    ADDCLASS(this, super, access, constants)            \
  25.     classThis = addClass(this, super, access, constants);        \
  26.     if (classThis == 0) {                        \
  27.         throwException(ClassFormatError);            \
  28.     }
  29.  
  30. /*
  31.  * Add the interfaces.
  32.  */
  33. #define    READINTERFACES(fp, this, count)                    \
  34.     do {                                \
  35.         createInfo cinfo;                    \
  36.         classes** interfaces;                    \
  37.         u2 iface;                        \
  38.         int i;                            \
  39.         if (count == 0) {                    \
  40.             return;                        \
  41.         }                            \
  42.         interfaces = (classes**)calloc(sizeof(classes**), count);\
  43.         if (interfaces == 0) {                    \
  44.             throwException(OutOfMemoryError);        \
  45.         }                            \
  46.         for (i = 0; i < count; i++) {                \
  47.             readu2(&iface, fp);                \
  48.             getClass(iface, this->constants, &cinfo);    \
  49.             interfaces[i] = cinfo.class;            \
  50.         }                            \
  51.         addInterfaces(this, count, interfaces);            \
  52.     } while(0)
  53.  
  54. /*
  55.  * Read in a field.
  56.  */
  57. #define    READFIELD(fp, this)                        \
  58.     do {                                \
  59.         field_info f;                        \
  60.         readu2(&f.access_flags, fp);                \
  61.         readu2(&f.name_index, fp);                \
  62.         readu2(&f.signature_index, fp);                \
  63.         addField(this, &f);                    \
  64.     } while (0)
  65.  
  66. /*
  67.  * Read in a method.
  68.  */
  69. #define    READMETHOD(fp, this)                        \
  70.     do {                                \
  71.         method_info m;                        \
  72.         readu2(&m.access_flags, fp);                \
  73.         readu2(&m.name_index, fp);                \
  74.         readu2(&m.signature_index, fp);                \
  75.         methodThis = addMethod(this, &m);            \
  76.     } while(0)
  77.  
  78.  
  79. /*
  80.  * Process the attributes.
  81.  */
  82. #define    READATTRIBUTE(fp, this, method)                    \
  83.     do {                                \
  84.         u2 idx;                            \
  85.         u2 len;                            \
  86.         readu2(&idx, fp);                    \
  87.         readu4(&len, fp);                    \
  88. DBG(        printf("Attribute '%s'\n", (char*)this->constants->data[idx]); )\
  89.         if (this->constants->tags[idx] == CONSTANT_Utf8 &&    \
  90.             strcmp((char*)this->constants->data[idx], "Code") == 0) {\
  91.             addCode(method, len, fp);            \
  92.         }                            \
  93.         else {                            \
  94.             seekm(fp, len);                    \
  95.         }                            \
  96.     } while(0)
  97.  
  98. #endif
  99.